package composite.example;

import java.util.List;

/**
 * @Author：LJ
 * @Description：
 * @Date: 2017/12/1
 * @Modified By:
 */
public class Client {
    public static void main(String[] args) {
        IBranch iBranch = compositionCorpTree();
        getTreeInfo(iBranch);
    }

    private static void getTreeInfo(IBranch branch) {
        List<ICorp> list = branch.getSub();
        for (ICorp i : list) {
            System.out.println(i.getInfo());
            if (i instanceof IBranch) {
                getTreeInfo((IBranch) i);
            }
        }
    }

    private static Branch compositionCorpTree() {
        Branch root = new Branch("Boos", "总裁", 100000);

        Branch dev = new Branch("zhang", "研发部经理", 10000);
        Branch sales = new Branch("Li", "销售部经理", 20000);
        Branch finance = new Branch("Liu", "财务部经理", 30000);
        root.addSub(dev);
        root.addSub(sales);
        root.addSub(finance);


        Branch firseLeader = new Branch("Huang", "一组组长", 100000);
        dev.addSub(finance);
        Branch secondLeader = new Branch("Wang", "二组组长", 100000);
        sales.addSub(secondLeader);

        firseLeader.addSub(new Leaf("a", "开发人员", 2000));
        firseLeader.addSub(new Leaf("b", "开发人员", 2000));
        secondLeader.addSub(new Leaf("c", "销售人员", 2000));

        return root;
    }
}
